<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%furniture}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%furniture_type}}`
 */
class m230605_094507_create_furniture_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%furniture}}', [
            'id' => $this->primaryKey(),
            'id_type' => $this->integer()->notNull(),
            'brand' => $this->string(),
            'scheme_img' => $this->string(),
            'color' => $this->string(),
            'dimensions_height' => $this->integer(),
            'dimensions_width' => $this->integer(),
            'dimensions_depth' => $this->integer(),
            'amount' => $this->integer(),
        ]);

        // creates index for column `id_type`
        $this->createIndex(
            '{{%idx-furniture-id_type}}',
            '{{%furniture}}',
            'id_type'
        );

        // add foreign key for table `{{%furniture_type}}`
        $this->addForeignKey(
            '{{%fk-furniture-id_type}}',
            '{{%furniture}}',
            'id_type',
            '{{%furniture_type}}',
            'id',
            'RESTRICT'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%furniture_type}}`
        $this->dropForeignKey(
            '{{%fk-furniture-id_type}}',
            '{{%furniture}}'
        );

        // drops index for column `id_type`
        $this->dropIndex(
            '{{%idx-furniture-id_type}}',
            '{{%furniture}}'
        );

        $this->dropTable('{{%furniture}}');
    }
}
